import { _decorator, Label, size, Sprite, UITransform } from 'cc';
import { Ab_BasePopUp_bA } from '../../../A-FRAME/component/ui.pop-up';
import Ab_GameAssets_bA from '../../manager/game.assets';
import { Ab_GamePopup_bA } from '../page/popup.game';
const { ccclass, property } = _decorator;

@ccclass('Ab_GameVictory_bA')
export class Ab_GameVictory_bA extends Ab_BasePopUp_bA<typeof Ab_GamePopup_bA, null> {
	protected Ab_default_return_bA: null;

	private lbl_round: Label;

	protected Ab_initAfterOnLoad_bA(){
		this.Ab_renderLocalUI_bA();
		this.lbl_round = this.node.getChildByName('lbl-round').getComponent(Label);
	}

	public Ab_onShow_bA(round: number){
		Ab_BasePopUp_bA.Ab_jelly_enter_bA(this.node);
		this.lbl_round.string = Ab_GameAssets_bA.Ab_getLangText_bA(0, round);

		abi.Ab_delay_bA(1.5, 'end')
		.then(()=>Ab_BasePopUp_bA.Ab_jelly_leave_bA(this.node))
		.then(()=>this.Ab_close_bA(null));
	}

	private Ab_renderLocalUI_bA(){
		let ui_head = this.node.getChildByName('head').getComponent(UITransform);
		let head_size = size(
			this.node.getChildByName('background-head').getComponent(UITransform).width,
			ui_head.height
		);

		let sframe = Ab_GameAssets_bA.Ab_getLangTexture_bA(6);

		let scale = Math.min(head_size.width/sframe.originalSize.width, head_size.height/sframe.originalSize.height);

		ui_head.getComponent(Sprite).spriteFrame = sframe;

		ui_head.setContentSize(
			sframe.originalSize.width * scale,
			sframe.originalSize.height * scale
		);
	}
}

